package com.tencent.cloud.uikit.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.StyleRes;

/**
 * 提示框
 *
 * @author vinsonhuang
 * @date 2018/6/25
 */
public class ToolTip {

    private Context mContext;

    private String mTitle;

    private String mContent;

    private String mCancelButtonTitle;

    private String mConfirmButtonTitle;

    private ActionListener mCancelListener;

    private ActionListener mConfirmListener;

    private Dialog mDialog;

    @StyleRes
    private int mStyle;

    private ToolTip() {
    }

    private ToolTip(Context context) {
        mContext = context;
    }

    public Context getContext() {
        return mContext;
    }

    public String getTitle() {
        return mTitle;
    }

    public String getContent() {
        return mContent;
    }

    public String getCancelButtonTitle() {
        return mCancelButtonTitle;
    }

    public String getConfirmButtonTitle() {
        return mConfirmButtonTitle;
    }

    public void setDialog(Dialog dialog) {
        mDialog = dialog;
    }

    public Dialog getDialog() {
        return mDialog;
    }

    public void dismiss() {
        if (null != mDialog && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

    public ActionListener getCancelListener() {
        return mCancelListener;
    }

    public ActionListener getConfirmListener() {
        return mConfirmListener;
    }

    public int getStyle() {
        return mStyle;
    }

    public static class Builder {

        private ToolTip mToolTip;

        public Builder() {
            mToolTip = new ToolTip();
        }

        public Builder(Context context) {
            mToolTip = new ToolTip(context);
        }

        public Builder title(String title) {
            mToolTip.mTitle = title;
            return this;
        }

        public Builder content(String content) {
            mToolTip.mContent = content;
            return this;
        }

        public Builder cancelButtonTitle(String cancelButtonTitle) {
            mToolTip.mCancelButtonTitle = cancelButtonTitle;
            return this;
        }

        public Builder confirmButtonTitle(String confirmButtonTitle) {
            mToolTip.mConfirmButtonTitle = confirmButtonTitle;
            return this;
        }

        public Builder cancelListener(ActionListener cancelListener) {
            mToolTip.mCancelListener = cancelListener;
            return this;
        }

        public Builder confirmListener(ActionListener confirmListener) {
            mToolTip.mConfirmListener = confirmListener;
            return this;
        }

        public Builder style(@StyleRes int style) {
            mToolTip.mStyle = style;
            return this;
        }

        public ToolTip build() {
            return mToolTip;
        }
    }

    public interface ActionListener {
        void onClick(ToolTip toolTip);
    }
}
